import javax.swing.*;
import java.awt.*;

/**
 * Rendering tools.
 * If center = -1, then that means do not draw the center (it is not determ.)
 */

public class Draw extends JPanel
{
	int siteSize = 5;
	Ising ic;
	int center;

	public Draw (Ising ic) { this (ic, -1); }

	public Draw (Ising ic, int center)
	{
		this.center = center;
		this.ic = ic; // Get ising information for a render operation
		if (ic.d != 2) 
			{ System.err.println ("Cannot render d="+ic.d); System.exit (1); }

		JFrame frame = new JFrame ();
		frame.getContentPane ().add (this);
		frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
		// Add values to account for window borders on my system (compiz thing)
		frame.setSize (siteSize*ic.L+10, siteSize*ic.L+27); 
		frame.setVisible (true);
	}

	public void paint (Graphics g)
	{
		int x0=0, y0=0;
		for (int i=0; i<ic.N; ++i)
		{
			x0 = siteSize*(i % ic.L);
			y0 = siteSize*(i / ic.L);
			if (i == center) g.setColor (Color.red);
			else if (ic.getSpin(i)==-1) g.setColor (Color.yellow);
			else g.setColor (Color.blue);
			g.fillRect (x0, y0, siteSize, siteSize);
		}
	}
}
